﻿using FluorineFx.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace lxwmvc
{
    [weixin(typeof(WeiXin_UserInfo), weixincontroller.URL, weixincontroller.SCOPE)]
    public class defaultcontroller
    {
        public static void a2(pagebase pb)
        {

        }

        

        public static void a(pagebase pb)
        {
            var jssdk = weixincontroller.GZH.JSSDK();
            pb["jssdk"] = jssdk;
        }
        /// <summary>
        /// 显示文章，分享文章
        /// </summary>
        /// <param name="pb"></param>
        public static void s(pagebase pb)
        {
            //应该要建立一个用户池，直接重用户池中拿到文章；
            //文章的阅读计数在这里触发
            //aid为空，重定向到默认广告页
            var code = pb.v_ss("code");
            _Articles art = queryhelper.get<_Articles>("select * from Articles where code=@0", code);

            //阅读次数增加
            queryhelper.execute("update Articles set ReadCount=ReadCount+1 where code=@0", code);
            
            //输出10条记录
            var arts = queryhelper.query<_Articles>("select top 10 * from Articles where  code<>@0 and ZTBUserID=@1 order by id desc", code,art.ZTBUserID);

            var ads = queryhelper.query<_ZTBAD>("select top 3 * from ztbad where ZTBUserID=@0 order by xuhao asc", art.ZTBUserID);

            pb["arts"] = arts;
            pb["ads"] = ads;

            using (StreamReader sr = new StreamReader(art.URL))
            {
                pb["body"] = sr.ReadToEnd();
            }

            //微信朋友圈分析处理
            pb["art"] = art;
            pb["img"] = "http://" + weixincontroller.domain + art.ImageUrl.Replace("\\", "/");
            pb["purl"] = "http://" + weixincontroller.domain + "/s?code=" + code;
            pb["domain"] = weixincontroller.domain;

            //输出js签名
            weixincontroller.GZH.JSSDK_FX();

            //noncestr url jsapi_ticket timestamp signature
            //
            var jssdk = weixincontroller.GZH.JSSDK();
            pb["jssdk"] = jssdk;
        }

        /// <summary>
        /// 群发消息
        /// </summary>
        /// <param name="pb"></param>
        //public static void sendall(pagebase pb)
        //{
        //    pb.cancelview();

        //    var t = GZH.SendTextContent("hello");
        //    pb.write(t);
        //}

        

        //public static void index(pagebase pb)
        //{
        //    var v = GZH.GetToken();

        //    //pb.write(JavaScriptConvert.SerializeObject(v));
        //    //pb.write("<br/>");

        //    //var v2 = gzh.GetCallBackip(v.access_token);
        //    //pb.write(JavaScriptConvert.SerializeObject(v2));
        //    //pb.write("<br/>");
        //}

        
    }
}
